<template>

<el-container class="home_contaner">
  <el-header >
  <div class="header_left">
   电商后台管理
  </div>
  <el-button type="info" @click="tuichu">退出</el-button>
  </el-header>

  <!-- 侧边栏 -->
  <el-container>
    <el-aside :width="isCollapse?'64px':'300px'">
    <div class="cone"  @click="toggleCollapse">|||</div>
      <el-menu
      :default-active="activePath"
      router
      :collapse="isCollapse"
      unique-opened
      default-active="2"
      background-color="#333744"
      text-color="#fff"
      active-text-color="#409eef">
      <el-submenu :index="item.id+''" v-for="item in menulist" :key="item.id">
        <template slot="title">
          <i :class="iconsObj[item.id]"></i>
          <span>{{item.authName}}</span>
        </template>
        <!-- 二级菜单 -->
        <el-menu-item @click="saveNavState('/' + item1.path)"
        :index="'/'+item1.path" v-for="item1 in item.children" :key="item1.id">
          <template slot="title">
          <i class="el-icon-menu"></i>
          {{item1.authName}}
          </template>
     
        </el-menu-item>
        </el-submenu>
      </el-submenu> 
    </el-menu>
    </el-aside>

    <!-- 主体区域 -->
    <el-main>
   <router-view />
    </el-main>
  </el-container>
</el-container>

</template>
<script>
export default{
    data(){
        return{
          menulist:{},
          activePath:'',
          isCollapse:false,
            iconsObj: {
        '125': 'iconfont icon-user',
        '103': 'iconfont icon-tijikongjian',
        '101': 'iconfont icon-shangpin',
        '102': 'iconfont icon-danju',
        '145': 'iconfont icon-baobiao'
      }, 
        }
    },
    created(){
      this.getMenuList()
        this.activePath = window.sessionStorage.getItem('activePath')
    },
    methods:{
      //退出
        tuichu(){
            window.sessionStorage.clear()
            this.$router.push("/login")
        },
        //左侧菜单数据
        async getMenuList(){
          let {data:res}=await this.$http.get("menus")
          console.log(res)
           this.menulist=res.data
        },
        //菜单的折叠
        toggleCollapse(){
          this.isCollapse=!this.isCollapse
        },
            // 保存链接的激活状态
    saveNavState(activePath) {
      window.sessionStorage.setItem('activePath', activePath)
      this.activePath = activePath
    },
    }
}
</script>

<style lang="less" scope>
.cone{
  background-color: #4a5064;
  line-height: 24px;
  font-size: 18px;
  text-align: center;
  letter-spacing: 0.2em;
  cursor: pointer;
}
.home_contaner{
    height:100%;
}
.iconfont{
  margin-right:10px;
}
.el-header{
  height:70px !important;
    background-color:#373d41;
    display:flex;
    justify-content:space-between;
    align-items:center;
    .header_left{
       height:60px;
       line-height:60px;
       color:#ccc;
       font-size:28px;
    }
    .el-button{
        height:40px;
    }
}
.el-aside{
    background-color:#373541;
    .el-menu{
  border-right:none;
 
}
}
.el-main{
    background-color:#eaedf1;
    flex:1;
}

</style>